import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

	public class UserOutput{

		DataOutputStream out;
		double LP;
		float EP;
		int RP;
		boolean sendOut;
		boolean run;
		int breaks;
		Player player;
		public UserOutput(DataOutputStream out, Player player)
		{
			this.breaks = 0;
			this.out = out;
			this.LP = 0;
			this.EP = 0;
			this.RP = 0;
			sendOut = true;
			this.run = true;
			this.player = player;
		} 
		private String getPlayerData()
		{
			String ans = "Center" + paddZeros((int)(player.getCurrentPosition().getX()) + "",7) 
					+ paddZeros((int)(player.getCurrentPosition().getY()) + "",7) + "\n";
			return ans;
			//String temp = "HP: " + player.getHP() + "\n";
			//temp = temp + "EP: " + player.getEP() + "\n";
			//temp = temp + "RP: " + player.getRP() + "\n";
			//return temp;
		}
		public String paddZeros(String str,int length)
		{
			String a = str + "";
			if(a.length() > length)
			{
				str = str.substring(0,length);
			}
			while(a.length() < length)
			{
				if(str.charAt(0) == '-')
				{
					String temp = "-0" + a.substring(1);
					a = temp;
				}
				else
				{
					a = "0" + a;
				}
			}
			return a;
		}
		/**
		 * sends the user a string representation of what to draw on the screen
		 * @param data
		 */
		public void sendData(String data)
		{
				if(data == "null")
				{
					data = "";
				}
				try {
					String emergency = "";
					if(player.characterSet() == false)
					{
						emergency = "Send ID\n";
					}
					out.writeUTF(emergency + data + getPlayerData());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					if(breaks >=600)
					{
						run = false;
						try {
							out.close();
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}
					System.out.println(e);
					breaks++;
				}
		}
		/**
		 * will no longer send data to this user
		 */
		public void stop()
		{
			run = false;
		}
		/**
		 * allows this "thread" to run, meaning that it will attemp to send the
		 * supplied information to the user
		 */
		public void start()
		{
			run = true;
		}
		/**
		 * sets the output stream to be used
		 * @param out
		 */
		public void setOutputStream(DataOutputStream out)
		{
			this.out = out;
		}
	}